import { axios } from "../utils/request";
import { ResPage } from "@/views/login/data.ts";
import { IUser } from "@/utils/types/IUser.ts";

export interface LoginFormState {
  username: string;
  password: string;
  code: string;
  uuid: string;
}

export interface LoginResponse {
  code: number;
  msg: string;
  token?: string;
}

export interface UserInfoResponse extends LoginResponse {
  permissions: string[];
  user: IUser;
}

export const codeImage = (): Promise<ResPage<never>> => {
  return axios.get("/captchaImage");
};

export const loginPost = (
  params: LoginFormState,
): Promise<ResPage<LoginResponse>> => {
  // return axios.post("/auth/token/login", params)
  return axios({
    // headers: { UserSource: userSource },
    method: "post",
    url: "/login",
    // params: { uuid: params.uuid, code: params.code },
    data: {
      username: params.username,
      password: params.password,
      uuid: params.uuid,
      code: params.code,
    },
  });
};

export const getRouters = () => {
  return axios.get("/getRouters");
};

// 获取用户详细信息
export function getInfo(): Promise<UserInfoResponse> {
  return axios({
    url: "/getInfo",
    method: "get",
  });
}

export const refreshToken = (refresh_token: string) => {
  return axios({
    url: "/auth/token/refresh_token",
    method: "post",
    params: refresh_token,
  });
};

// 通知中心下拉框
export function getRoleDrDropDown() {
  return axios({
    url: "/system/role/dropDown",
    method: "get",
  });
}
